<template>
<div>
  <myPage></myPage>
  <div>
    <el-table :data="offlineOrders" height="560px">
      <el-table-column label="下单时间" align="center" :formatter="timer"></el-table-column>
      <el-table-column label="姓名" align="center" prop="name"></el-table-column>
      <el-table-column label="联系方式" align="center" prop="phone"></el-table-column>
      <el-table-column label="位置" align="center" prop="position"></el-table-column>
      <el-table-column label="回收方式" align="center" prop="way" :filters="wayFil" :filter-method="wayFilFunc"></el-table-column>
      <el-table-column label="状态" align="center" prop="statu" :filters="statuFil" :filter-method="statuFilFunc">
        <template slot-scope="scope">
          <el-button v-if="scope.row.statu === 201" type="text" size="small" @click="confirmSale(scope.row)">待售出</el-button>
          <span v-if="scope.row.statu === 200">已完成</span>
          <span v-if="scope.row.statu === 202">已取消</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <div v-if="scope.row.statu === 201">
            <el-button type="danger" size="mini" @click="cancel(scope.row)">取消</el-button>
          </div>
            <el-button v-if="scope.row.statu !== 201" type="primary" size="small">查看</el-button>
        </template>
        <template>

        </template>
      </el-table-column>
    </el-table>
  </div>
</div>
</template>

<script>
import myPage from "@/components/my-page";
export default {
  name: "offlineOrder",
  components:{myPage},
  data(){
    return{
      offlineOrders:[],
      statuFil:[
        {text:'已完成',value:200},
        {text: '待售出',value:201},
        {text: '已取消',value:202},
      ],
      wayFil:[
        {text:'邮寄',value:'邮寄'},
        {text: '上门收货',value: '上门收货'},
      ]
    }
  },
  mounted() {
    this.getOfflineOrder();
  },
  methods:{
    confirmSale(row){
      console.log(row)
      this.axios.put('/api/confirmSale',{
        id:row._id
      }).then(res=>{
        console.log(res)
      }).catch(err=>{
        console.log(err)
      })
    },
    cancel(row){
      this.axios.patch('/api/cancelOffline',{
        id:row._id
      }).then(res=>{
        console.log(res);
        this.getOfflineOrder();
      }).catch(err=>{
        console.log(err)
      })
    },
    timer(row) {
      var moment = require('moment');
      if (row.time == undefined){
        return "暂无数据"
      }else {
        var times = moment(row.time).format('YYYY-MM-DD HH:MM:SS')
        return times
      }
    },
    getOfflineOrder(){
      this.axios.get('/api/getOfflineOrder',{
        params:{
          Uid:window.sessionStorage.getItem('id')
        }
      }).then(res=>{
        console.log(res.data);
        this.offlineOrders = res.data;
      }).catch(err=>{
        console.log(err)
      })
    },
    statuFilFunc(value,row){
      console.log(value,row);
      return row.statu === value
    },
    wayFilFunc(value,row){
      return row.way === value
    }
  }
}
</script>

<style scoped>
</style>
